/**
 * 
 */
package com.honghao.student.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.honghao.student.dao.StudentDao;
import com.honghao.student.pojo.Student;
import com.honghao.student.service.IStudentService;



/**
 * @author honghao.li
 *
 */
@Service
@Qualifier("StudentServiceImpl")
public class StudentServiceImpl implements IStudentService{
	
	private static final Logger LOGGER = LoggerFactory
            .getLogger(StudentServiceImpl.class);
    
	@Autowired
    private StudentDao studentDao;
    
    /**
     * 
     * @return
     */
    @Cacheable(value="studentInfo")
    public List<Student> getAllStudent(){
    	LOGGER.info("querying db...");
        return studentDao.selectAll();
    }
    
    /**
     *
     * @param student
     */
    @CacheEvict(value="studentInfo")
    public void updateStudent(Student student){
    	//UpdateDB
    }
    
    @CacheEvict(value="studentInfo",allEntries=true)
    public void register(Student student){
        LOGGER.info("add student for business");
        studentDao.save(student);
        throw new RuntimeException("add error");
    }
    
    public void delete(int stuId){
        LOGGER.info("del student for business");
        studentDao.delete(stuId);
    }
    /**
     * 
     */
    @CacheEvict(value="studentInfo",allEntries=true,beforeInvocation=true)
    public void reload(){
    	
    }
    
}
